var express = require('express');
var router = express.Router();
var qrcode = require('qr-image');
var path = require('path');
var fs = require('fs');
/* GET home page. */
router.get('/', function(req, res, next) {
  var text = req.query.text;
  var qrimg = qrcode.image(text,{margin:1,size:20});
  var stream = qrimg.pipe(fs.createWriteStream(path.resolve(__dirname, '../public/images/qr-code.png')));
  stream.on('finish',function(){
      res.render('qrcode', { imgurl: '/images/qr-code.png' });
  })
});

module.exports = router;
